package com.ruoyi.salary.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.salary.domain.HrSalaryPayment;
import com.ruoyi.salary.service.IHrSalaryPaymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 薪酬发放Controller
 * 
 * @author gy
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/salary/payment")
public class HrSalaryPaymentController extends BaseController
{
    @Autowired
    private IHrSalaryPaymentService hrSalaryPaymentService;

    /**
     * 查询薪酬发放列表
     */
    @PreAuthorize("@ss.hasPermi('salary:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(HrSalaryPayment hrSalaryPayment)
    {
        startPage();
        List<HrSalaryPayment> list = hrSalaryPaymentService.selectHrSalaryPaymentList(hrSalaryPayment);
        return getDataTable(list);
    }

    /**
     * 导出薪酬发放列表
     */
    @PreAuthorize("@ss.hasPermi('salary:payment:export')")
    @Log(title = "薪酬发放", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HrSalaryPayment hrSalaryPayment)
    {
        List<HrSalaryPayment> list = hrSalaryPaymentService.selectHrSalaryPaymentList(hrSalaryPayment);
        ExcelUtil<HrSalaryPayment> util = new ExcelUtil<HrSalaryPayment>(HrSalaryPayment.class);
        util.exportExcel(response, list, "薪酬发放数据");
    }

    /**
     * 获取薪酬发放详细信息
     */
    @PreAuthorize("@ss.hasPermi('salary:payment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hrSalaryPaymentService.selectHrSalaryPaymentById(id));
    }

    /**
     * 新增薪酬发放
     */
    @PreAuthorize("@ss.hasPermi('salary:payment:add')")
    @Log(title = "薪酬发放", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HrSalaryPayment hrSalaryPayment)
    {
        return toAjax(hrSalaryPaymentService.insertHrSalaryPayment(hrSalaryPayment));
    }

    /**
     * 修改薪酬发放
     */
    @PreAuthorize("@ss.hasPermi('salary:payment:edit')")
    @Log(title = "薪酬发放", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HrSalaryPayment hrSalaryPayment)
    {
        return toAjax(hrSalaryPaymentService.updateHrSalaryPayment(hrSalaryPayment));
    }

    /**
     * 删除薪酬发放
     */
    @PreAuthorize("@ss.hasPermi('salary:payment:remove')")
    @Log(title = "薪酬发放", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hrSalaryPaymentService.deleteHrSalaryPaymentByIds(ids));
    }
}
